01 / 03

What does the href attribute in <a> do?

Role of the href Attribute in <a>

The href attribute in the <a> (anchor) tag specifies the URL or location that the link should point to. When a user clicks the link, the browser navigates to the resource defined in href.

Key Points about href
  1. 1

    It defines the destination of the hyperlink (a webpage, file, email address, or part of the same page).

  2. 2

    If href is missing, the <a> element won’t work as a link.

  3. 3

    You can use absolute URLs (e.g., https://example.com) or relative URLs (e.g., /about.html).

  4. 4

    Special values like mailto:someone@example.com open an email client, and tel:+123456789 initiates a phone call on supported devices.

Example Usage

In short: The href attribute defines the target address of a hyperlink, making the <a> tag functional.